package Arithmetic;

public class SortMethordReview {

	/**
	 * @param argsO
	 */
	public static void main(String[] args) {
		bubbleSort(new int[]{5,5,3,1});
	}
	
	
	
	public static void straightInsert(int[] src){
			for(int i = 1; i<src.length ; ++i){
				int j = i - 1;
				int curr = src[i];
				while(j>=0 && curr < src[j]){
					src[j+1] = src[j];
					j--;
				}
				src[j+1] = curr;
			}
			
			for(int i : src){
				System.out.print(i + "   ");
			}
	}
	
	public static void selectSort(int[] src){
		for(int i =0; i < src.length - 1;++i){
			int index = i;
			int min = src[i];
			for(int j=i+1;j<src.length;j++){
				if(min > src[j]){
					min = src[j];
					index = j;
				}
			}
			if(i!=index){
				int tmp = src[index];
				src[index] = src[i];
				src[i] = tmp;
			}
		}
		
		for(int i : src){
			System.out.print(i + "   ");
		}
	}
	
	public static void bubbleSort(int[] src){
		for(int i = 0; i < src.length -1 ; ++i){
			for(int j = 0 ; j< src.length -1 -i; j++){
				if(src[j] > src[j+1]){
					int tmp = src[j];
					src[j] = src[j+1];
					src[j+1] = tmp;
				}
			}
		}
		for(int i : src){
			System.out.print(i + "   ");
		}
	}

}
